#!/bin/sh


echo "Dckerfile shell脚本"

#Dckerfile shell脚本

# 1 用cat 生成 DockerFile 文件









#配置服务启动 /etc/supervisord.d/sshd.ini
cat > sshd.ini << EOF 
[supervisord]
nodaemon=true
[program:ssh]
command=/usr/sbin/sshd -D
EOF






cat > Dockerfile << EOF
#导入镜像
FROM centos/aarch64


#安装 服务软件

RUN yum -y install epel-release 
RUN yum -y install supervisor 
RUN yum -y install passwd 
RUN yum -y install openssl 
RUN yum -y install openssh-server 
RUN yum -y install vim
#复制启动服务配置文件
COPY sshd.ini /etc/supervisord.d/sshd.ini

#配置ssh服务
RUN ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ''  
RUN ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N '' 

RUN sed -i "s/#UsePrivilegeSeparation.*/UsePrivilegeSeparation no/g" /etc/ssh/sshd_config


RUN sed -i "s/UsePAM.*/UsePAM yes/g" /etc/ssh/sshd_config

#修改root密码
RUN echo "1813033378" | passwd --stdin root

LABEL u="root 1813033378"
#运行程序 supervisord -c /etc/supervisord.conf
 # 定参
ENTRYPOINT ["supervisord", "-c"]
 # 变参
CMD ["/etc/supervisord.conf"] 





EOF
sync
#构建镜像
docker build -f $(pwd)/Dockerfile -t hq/centos7-ssh $(pwd)/

#supervisor
#supervisord
#supervisorctl -c /etc/supervisord.conf reload
#启动容器
docker run --name ssh --restart=always -d -p 1022:22 hq/centos7-ssh
docker run --name bt --restart=always -d -p 2222:22 -p 8888:8888 -p 80:80 hq/centos7-ssh
#docker update --restart=always ssh
echo "删除构建文件"
rm -fv sshd.ini Dockerfile
